//商品分类全局组件的仓库
import { defineStore } from 'pinia'
import { ref } from 'vue'
//引入api
import {
  reqCategoryList1,
  reqCategoryList2,
  reqCategoryList3,
} from '../../api/product/attr'

let useCategoryStore = defineStore('category', () => {
  //一级分类列表
  const c1List = ref()
  //一级分类id
  const c1Id = ref()
  //二级分类列表
  const c2List = ref()
  //二级分类id
  const c2Id = ref()
  //三级分类列表
  const c3List = ref()
  //三级分类id
  const c3Id = ref()
  //存储属性列表及表格配置数据
  const attrList = ref()

  //获取一级分类列表
  const getC1List = async () => {
    let result = await reqCategoryList1()
    if (result.code == 200) {
      c1List.value = result.data
    }
  }
  //获取二级分类列表
  const getC2List = async () => {
    let result = await reqCategoryList2(c1Id.value)
    if (result.code == 200) {
      c2List.value = result.data
    }
  }
  //获取三级分类列表
  const getC3List = async () => {
    let result = await reqCategoryList3(c2Id.value)
    if (result.code == 200) {
      c3List.value = result.data
    }
  }

  return {
    c1List,
    c1Id,
    getC1List,
    c2List,
    c2Id,
    getC2List,
    c3List,
    c3Id,
    getC3List,
    attrList,
  }
})

export default useCategoryStore
